package com.echovin.esb.gateway.mapper;

import com.echovin.esb.gateway.model.GatewayParameterSchema;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GatewayParameterValidateMapper {
    @Select("select * from GATEWAY_PARAMETER_SCHEMA")
    List<GatewayParameterSchema> getParameterValidates();

    @SelectKey(keyProperty = "record.id", resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Options(keyProperty = "record.id", useGeneratedKeys = true)
    @Insert("insert into GATEWAY_PARAMETER_SCHEMA(ID,ACTION_ID,CHECK_TYPE,SCHEMA,CREATER,CREATE_TIME) " +
            "values(#{record.id},#{record.actionId},#{record.checkType},#{record.schema},#{record.creater},#{record.createTime})")
    int insert(@Param("record") GatewayParameterSchema record);

    @Update("update GATEWAY_PARAMETER_SCHEMA set IS_DELETE = 1, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ACTION_ID = #{record.actionId}")
    int delete(GatewayParameterSchema record);

    @Update("update GATEWAY_IP_LIMIT_API set CHECK_TYPE = #{record.checkType}, SCHEMA = #{record.schema}, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ID = #{record.id}")
    int update(GatewayParameterSchema record);
}
